Back to course home
0% completed
Vote For New Content
LinkedIn Medium
Rotate List (medium)
Solution: Rotate List
Find Leaves of Binary Tree (medium)
Solution: Find Leaves of Binary Tree
Valid Triangle Number (medium)
Solution: Valid Triangle Number
Valid Parenthesis String (medium)
Solution: Valid Parenthesis String
Edit Distance (medium)
Solution: Edit Distance
Remove All Ones With Row and Column Flips II (medium)
Solution: Remove All Ones With Row and Column Flips II
Reverse Integer (medium)
Solution: Reverse Integer
Triplet Sum to Zero (medium)
Solution: Triplet Sum to Zero
Longest Substring Without Repeating Characters (medium)
Solution: Longest Substring Without Repeating Characters (medium)
Decode Ways (medium)
Solution: Decode Ways
Quadruple Sum to Target (medium)
Solution: Quadruple Sum to Target
Next Permutation (medium)
Solution: Next Permutation
Search in Rotated Array (medium)
Solution: Search in Rotated Array
Word Search (medium)
Solution: Word Search
Remove Nth Node From End of List (Medium)
Solution: Remove Nth Node From End of List
House Robber II (medium)
Solution: House Robber II
Coin Change
Solution: Coin Change
Design Add and Search Words Data Structure (medium)
Solution: Design Add and Search Words Data Structure
Merge Intervals (medium)
Solution: Merge Intervals
Number of Islands (easy)
Solution: Number of Islands
Longest Palindromic Subsequence (medium)
Solution: Longest Palindromic Subsequence
Kth Smallest Number (medium)
Solution: Kth Smallest Number
Maximum Product Subarray (medium)
Solution: Maximum Product Subarray
Same Tree (medium)
Solution: Same Tree
LinkedIn Hard
Max Points on a Line (hard)
Solution: Max Points on a Line
Closest Binary Search Tree Value II (hard)
Solution: Closest Binary Search Tree Value II
Word Ladder (hard)
Solution: Word Ladder
Median of Two Sorted Arrays (hard)
Solution: Median of Two Sorted Arrays
Largest Rectangle in Histogram (hard)
Solution: Largest Rectangle in Histogram
Serialize and Deserialize Binary Tree (hard)
Solution: Serialize and Deserialize Binary Tree
Maximum Depth (or Height) of Binary Tree (easy)
Problem Statement
Given a root node of the binary tree, return the depth (or height) of a binary tree.
The Depth of the binary tree refers to the number of nodes along the longest path from the root node to the farthest leaf node. If the tree is empty, the depth is 0.
Examples
Example 1
- Input: root = [1, 2, 3, 4, 5]
- Expected Output: 3
- Explanation: The longest path is
1->2->4or1->2->5with 3 nodes.
Example 2
- Input: root = [1, null, 2, null, 3]
- Expected Output: 3
- Justification: There's only one path
1->2->3with 3 nodes.
Example 3
- Input: root = [1, 2, 3, 4, 7, null, null, null, null, null, 9]
- Expected Output: 4
- Justification: The longest path is
1->2->7->9with 4 nodes.
Constraints:
- The number of nodes in the tree is in the range [0, 104].
-100 <= Node.val <= 100
Try it yourself
Try solving this question here:
Java
Saved to Cloud
. . . .
Solution: Valid Perfect Square
Solution: Maximum Depth (or Height) of Binary Tree
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself